import { Component, OnInit, Inject } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ActivatedRoute} from '@angular/router';
import { SprofilesModule} from '../../../../../../service/delivent/sprofilesModule';
import { BranchModule} from '../../../../../../service/delivent/brachModule';
import * as _ from 'lodash';
import * as moment from 'moment';
import { View } from '@antv/data-set';


@Component({
  selector: 'app-deliveryDay',
  templateUrl: './deliveryDay.component.html',
   styleUrls: ['./deliveryDay.component.less']
})

export class DeliveryDayComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        public activatedRoute: ActivatedRoute,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
    ) { }
    profilesGuid: string; // 工作项guid
    token:any;
            sourceData = [];
            dv:any;
            forceFit: boolean= true;
            height: number = 400;
            data :any;
            style = { stroke: '#fff', lineWidth: 1 };

       
    ngOnInit() {

            this.token  = this.tokenService.get().seniortoken; // 绑定token
             this.profilesGuid = this.activatedRoute.snapshot.params.id;
             this.getData('7');
    }
        deliveryResults = appConfig.Enumeration.deliveryResults;

    
  listOfOption = [
      {label:'7天',value:'7'},
        {label:'14天',value:'14'},
          {label:'21天',value:'21'},
            {label:'30天',value:'30'},
  ]
  isSpinning = false;
  Mode = null;
    number = '15';
    isShow =false;
    scale = [{
             dataKey: 'time',
            //   sync: false
                        }];
  getData(it) {
         
              let label = []
              let labels = '';
              let datasets = [];
              this.sourceData = [];
              this.isSpinning = true;
              let dv = null;
        let url = '/sProfiles/'+this.profilesGuid+'/DeliveryDay/'+it
        this.utilityService.getData(appConfig.testUrl  + url )
            .subscribe(
                (val) => {
                     
                   
                  
                    val.result.forEach(element => {
                        element.P = parseInt(element.P)
                        element.E = parseInt(element.E)
                        element.D = parseInt(element.D)
                      this.sourceData.push({time:element.time,'项目':element.P,'生产事件':element.E,'需求':element.D})
                    });
           
                
                    dv = new View().source(this.sourceData);
                    dv.transform({
                    type: 'fold',
                    fields: ['项目','生产事件','需求'],
                    key: 'city',
                    value: 'temperature',
                    });
                    this.data = dv.rows;
                   
                     this.isSpinning = false;
        },(error)=>{
              this.isSpinning = false;
                 this.nznot.create('error', error.code , error.msg);
        });
    }
    getDetail(it){
   
    }


}
